home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / scherz programme / zoom_v1.5 / sources.lha / Sources / Zoom!.c
C/C++ Source or Header  |  1995-09-04  |  13KB  |  463 lines

  1. ;/*
  2. sc ignore=73 OPTIMIZE OPTSIZE OPTGO OPTPEEP NOSTKCHK Zoom!.c
  3. slink from lib:c.o Zoom!.o to /Zoom! LIB LIB:sc.lib LIB:amiga.lib SC SD ND NOICONS STRIPDEBUG
  4. delete Zoom!.o
  5. quit
  6.  
  7. */
  8.  
  9. #include <exec/memory.h>
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #include <intuition/intuitionbase.h>
  13. #include <graphics/gfx.h>
  14. #include <dos/dos.h>
  15. #include <devices/timer.h>
  16. #include <3AM/libraries/bitmap.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19.  
  20. #include <clib/alib_protos.h>
  21. #include <clib/exec_protos.h>
  22. #include <clib/dos_protos.h>
  23. #include <clib/graphics_protos.h>
  24. #include <clib/intuition_protos.h>
  25. #include <3AM/clib/bitmap_protos.h>
  26. #include <3AM/pragmas/bitmap_pragmas.h>
  27.  
  28. UWORD chip Lens_data[] = {
  29. 0x0000, 0x0000, 0x0000, 0x0700, 0x0700, 0x1FC0, 0x18C0, 0x37E0, 0x3060, 0x68B0, 0x2020, 0x5070,
  30. 0x4010, 0xA038, 0x4010, 0xA038, 0x4010, 0xA038, 0x2020, 0x5050, 0x3060, 0x48B0,
  31. 0x18F0, 0x2718, 0x0738, 0x18CC, 0x001C, 0x0726, 0x000E, 0x0013, 0x0004, 0x000E,
  32. 0x0000, 0x0004, 0x0000, 0x0000 };
  33.  
  34. UWORD chip SPlus_data[] = {
  35. 0x7FFF,0xC000,0x7FFF,0xC000,0x7F3F,0xC000,0x7F3F,0xC000,0x7807,0xC000,0x7F3F,0xC000,
  36. 0x7F3F,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0xFFFF,0x8000,0xFE1F,0x8000,
  37. 0xFEDF,0x8000,0xF0C3,0x8000,0xF7FB,0x8000,0xF0C3,0x8000,0xFEDF,0x8000,0xFE1F,0x8000,
  38. 0xFFFF,0x8000,0x8000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  39. 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 };
  40.  
  41. UWORD chip SMinus_data[] = {
  42. 0x7FFF,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0x7807,0xC000,0x7FFF,0xC000,
  43. 0x7FFF,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0xFFFF,0x8000,0xFFFF,0x8000,
  44. 0xFFFF,0x8000,0xF003,0x8000,0xF7FB,0x8000,0xF003,0x8000,0xFFFF,0x8000,0xFFFF,0x8000,
  45. 0xFFFF,0x8000,0x8000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  46. 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 };
  47.  
  48. UWORD chip SAutoPlus_data[] = {
  49. 0x7FFF,0xC000,0x7FFF,0xC000,0x767F,0xC000,0x66FF,0xC000,0x67E7,0xC000,0x7081,0xC000,
  50. 0x7FE7,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0xFFFF,0x8000,0xF07F,0x8000,
  51. 0xEFBF,0x8000,0xDFC3,0x8000,0xDF18,0x8000,0xEF7E,0x8000,0xF018,0x8000,0xFFC3,0x8000,
  52. 0xFFFF,0x8000,0x8000,0x0000 };
  53.  
  54. UWORD chip SAutoMinus_data[] = {
  55. 0x7FFF,0xC000,0x7FFF,0xC000,0x767F,0xC000,0x66FF,0xC000,0x67BF,0xC000,0x70FF,0xC000,
  56. 0x7F81,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0xFFFF,0x8000,0xF07F,0x8000,
  57. 0xEFBF,0x8000,0xDFDF,0x8000,0xDFDF,0x8000,0xEF00,0x8000,0xF07E,0x8000,0xFF00,0x8000,
  58. 0xFFFF,0x8000,0x8000,0x0000 };
  59.  
  60. struct Image SPlus_image = { 0,0,18,10,3,SPlus_data,7,0,0 };
  61. struct Image SMinus_image = { 0,0,18,10,3,SMinus_data,7,0,0 };
  62. struct Image SAutoPlus_image = { 0,0,18,10,2,SAutoPlus_data,3,0,0 };
  63. struct Image SAutoMinus_image = { 0,0,18,10,2,SAutoMinus_data,3,0,0 };
  64.  
  65. #define ZOOM_IN_GDG_ID    1
  66. #define ZOOM_OUT_GDG_ID    2
  67. #define AUTO_PLUS_GDG_ID 3
  68. #define AUTO_MINUS_GDG_ID 4
  69.  
  70. struct Gadget ZoomInGdg = {
  71.     NULL, -17, 0, 18, 10, GFLG_RELRIGHT | GFLG_GADGHCOMP | GFLG_GADGIMAGE,
  72.     GACT_RELVERIFY | GACT_RIGHTBORDER, GTYP_BOOLGADGET, &SPlus_image, NULL, NULL, 0L, NULL, ZOOM_IN_GDG_ID, NULL };
  73.  
  74. struct Gadget ZoomOutGdg = {
  75.     &ZoomInGdg, -17, 0, 18, 10, GFLG_RELRIGHT | GFLG_GADGHCOMP | GFLG_GADGIMAGE,
  76.     GACT_RELVERIFY | GACT_RIGHTBORDER, GTYP_BOOLGADGET, &SMinus_image, NULL, NULL, 0L, NULL, ZOOM_OUT_GDG_ID, NULL };
  77.  
  78. struct Gadget AutoPlusGdg = {
  79.     &ZoomOutGdg, -17, 0, 18, 10, GFLG_RELRIGHT | GFLG_GADGHCOMP | GFLG_GADGIMAGE,
  80.     GACT_RELVERIFY | GACT_RIGHTBORDER, GTYP_BOOLGADGET, &SAutoPlus_image, NULL, NULL, 0L, NULL, AUTO_PLUS_GDG_ID, NULL };
  81.  
  82. struct Gadget AutoMinusGdg = {
  83.     &AutoPlusGdg, -17, 0, 18, 10, GFLG_RELRIGHT | GFLG_GADGHCOMP | GFLG_GADGIMAGE,
  84.     GACT_RELVERIFY | GACT_RIGHTBORDER, GTYP_BOOLGADGET, &SAutoMinus_image, NULL, NULL, 0L, NULL, AUTO_MINUS_GDG_ID, NULL };
  85.  
  86. struct NewWindow nwt = {
  87.     60, 60, 142, 75, 0, 0, IDCMP_CLOSEWINDOW | IDCMP_MOUSEBUTTONS | IDCMP_GADGETUP | IDCMP_NEWSIZE,
  88.     WFLG_ACTIVATE | WFLG_SIZEGADGET | WFLG_SIZEBRIGHT | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_RMBTRAP,
  89.     &AutoMinusGdg, NULL, NULL, NULL, NULL, 120, 61, 0, 0, WBENCHSCREEN };
  90.  
  91. #define PROGRAM_NAME "Zoom! v1.5"
  92. #define AUTHORS_NAME "Stefano Reksten"
  93.  
  94. char *version = "$VER: Zoom! v1.5 (3.9.95) by Stefano Reksten";
  95.  
  96. char *SCR_NAME = PROGRAM_NAME" © 1995 by "AUTHORS_NAME;
  97. char *WND_NAME = PROGRAM_NAME" - S:00 - A:00";
  98.  
  99. struct IntuitionBase *IntuitionBase;
  100. struct GfxBase *GfxBase;
  101. struct Library *BitMapBase, *IconBase;
  102. struct Window *window;
  103.  
  104. struct BitMap *destBm;
  105. struct BitMapScaleInfo *sinfo;
  106. struct MsgPort *TimerMP;
  107. struct timerequest *TimerIO;
  108. ULONG time_delay;
  109. BOOL timer_running = FALSE;
  110.  
  111. UWORD height, width, lastX, lastY;
  112. UBYTE depth, scaling_factor = 2;
  113.  
  114. struct BitMapScaleInfo bsi;
  115.  
  116.  
  117. void FreeBitMaps( void )
  118. {
  119. if ( destBm )
  120.     DisposeBitMap( destBm );
  121. }
  122.  
  123.  
  124. BOOL AllocBitMaps( void )
  125. {
  126. width = ( window->Width - window->BorderLeft - window->BorderRight ) / scaling_factor;
  127. height = ( window->Height - window->BorderTop - window->BorderBottom ) / scaling_factor;
  128.  
  129. destBm = CreateBitMap( (width+1) * scaling_factor, (height+1) * scaling_factor, depth );
  130.  
  131. if ( destBm )
  132.     return TRUE;
  133. else
  134.     return FALSE;
  135. }
  136.  
  137.  
  138. void Zoom( void )
  139. {
  140. register UWORD X = lastX;
  141. register UWORD Y = lastY;
  142.  
  143. UWORD w = width * scaling_factor / 2;
  144. UWORD h = height * scaling_factor / 2;
  145.  
  146. UWORD sw = window->WScreen->Width;
  147. UWORD sh = window->WScreen->Height;
  148.  
  149. if ( X > w/scaling_factor )
  150.     X -= w/scaling_factor;
  151. else    X = 0;
  152.  
  153. if ( X > sw - width )
  154.     X = sw - width;
  155.  
  156. if ( Y > h/scaling_factor )
  157.     Y -= h/scaling_factor;
  158. else    Y = 0;
  159.  
  160. if ( Y > sh - height )
  161.     Y = sh - height;
  162.  
  163. RectFill( window->RPort, window->BorderLeft, window->BorderTop, window->Width - window->BorderRight, window->Height - window->BorderBottom );
  164. bsi.bsi_HorNum = scaling_factor;
  165. bsi.bsi_VertNum = scaling_factor;
  166. bsi.bsi_Width = width;
  167. bsi.bsi_Height = height;
  168. bsi.bsi_SrcLeftEdge = X;
  169. bsi.bsi_SrcTopEdge = Y;
  170. bsi.bsi_DestLeftEdge = /*window->LeftEdge + window->BorderLeft;*/0;
  171. bsi.bsi_DestTopEdge = /*window->TopEdge + window->BorderTop;*/0;
  172. ScaleBitMap( &bsi );
  173. BltBitMapRastPort( destBm, 0, 0, window->RPort, window->BorderLeft, window->BorderTop, width * scaling_factor, height * scaling_factor, 0xC0 );
  174. }
  175.  
  176.  
  177. BOOL SetUpTimer( void )
  178. {
  179. if ( TimerMP = CreateMsgPort() )
  180.     {
  181.     if ( TimerIO = (struct timerequest *)CreateExtIO(TimerMP, sizeof( struct timerequest ) ) )
  182.         {
  183.         if ( !(OpenDevice( "timer.device", UNIT_VBLANK, (struct IORequest *)TimerIO, 0 ) ) )
  184.             {
  185.             TimerIO->tr_node.io_Command = TR_ADDREQUEST;
  186.             TimerIO->tr_time.tv_secs = time_delay;
  187.             SendIO( (struct IORequest *)TimerIO );
  188.             return( TRUE );
  189.             }
  190.         DeleteExtIO( (struct IORequest *)TimerIO );
  191.         }
  192.     DeleteMsgPort( TimerMP );
  193.     }
  194. return( FALSE );
  195. }
  196.  
  197.  
  198. void RemoveTimer( void )
  199. {
  200. if ( TimerIO )
  201.     {
  202.     if ( !( CheckIO( (struct IORequest *)TimerIO ) ) )
  203.         AbortIO( (struct IORequest *)TimerIO );
  204.     WaitIO( (struct IORequest *)TimerIO );
  205.     CloseDevice( (struct IORequest *)TimerIO );
  206.     DeleteExtIO( (struct IORequest *)TimerIO );
  207.     DeletePort( TimerMP );
  208.     TimerIO = NULL;
  209.     }
  210. }
  211.  
  212.  
  213. void SetTitles( void )
  214. {
  215. WND_NAME[15] = '0' + scaling_factor / 10;
  216. WND_NAME[16] = '0' + scaling_factor % 10;
  217.  
  218. if ( !time_delay )
  219.     {
  220.     WND_NAME[22] = 'N';
  221.     WND_NAME[23] = 'A';
  222.     }
  223. else
  224.     {
  225.     if ( time_delay < 100 )
  226.         {
  227.         WND_NAME[22] = '0' + time_delay / 10;
  228.         WND_NAME[23] = '0' + time_delay % 10;
  229.         }
  230.     else
  231.         {
  232.         WND_NAME[22] = '?';
  233.         WND_NAME[23] = '!';
  234.         }
  235.     }
  236.  
  237. SetWindowTitles( window, WND_NAME, SCR_NAME );
  238. }
  239.  
  240. void ProcessMessages( void )
  241. {
  242. register BOOL stay = TRUE;
  243. register ULONG signal, mask = 1L<<window->UserPort->mp_SigBit | SIGBREAKF_CTRL_C;
  244. register struct IntuiMessage *msg;
  245. register struct Message *timerMsg;
  246. register struct Gadget *gdg;
  247. register ULONG class;
  248. register UWORD code;
  249.  
  250. while( stay )
  251.     {
  252.     if ( timer_running )
  253.         mask |= 1L<<TimerMP->mp_SigBit;
  254.  
  255.     signal = Wait ( mask );
  256.  
  257.     if ( signal & SIGBREAKF_CTRL_C )
  258.         stay = FALSE;
  259.  
  260.     if ( timer_running && signal & 1L<<TimerMP->mp_SigBit )
  261.         {
  262.         if ( timerMsg = GetMsg( TimerMP ) )
  263.             {
  264.             Zoom();
  265.             TimerIO->tr_node.io_Command = TR_ADDREQUEST;
  266.             TimerIO->tr_time.tv_secs = time_delay;
  267.             SendIO( (struct IORequest *)TimerIO );
  268.             }
  269.         }
  270.  
  271.     if ( signal & 1L<<window->UserPort->mp_SigBit )
  272.         {
  273.         while ( msg = (struct IntuiMessage *)GetMsg( window->UserPort ) )
  274.             {
  275.             class = msg->Class;
  276.             code = msg->Code;
  277.  
  278.             switch( class )
  279.                 {
  280.                 case IDCMP_CLOSEWINDOW:
  281.                     stay = FALSE;
  282.                     break;
  283.                 case IDCMP_NEWSIZE:
  284.                     FreeBitMaps();
  285.                     width = ( window->Width - window->BorderLeft - window->BorderRight -1 ) / scaling_factor;
  286.                     height = ( window->Height - window->BorderTop - window->BorderBottom -1 ) / scaling_factor;
  287.                     if ( stay = AllocBitMaps() )
  288.                         Zoom();
  289.                     break;
  290.                 case IDCMP_MOUSEBUTTONS:
  291.                     switch( code )
  292.                         {
  293.                         case MENUUP:
  294.                             lastX = IntuitionBase->MouseX;
  295.                             lastY = IntuitionBase->MouseY;
  296.                             if ( !( window->WScreen->ViewPort.Modes & LACE ) )
  297.                                 lastY >>= 1;
  298.                             if ( (window->WScreen->ViewPort.Modes & SUPERHIRES ) )
  299.                                 lastX <<= 1;
  300.                             else
  301.                             if ( !(window->WScreen->ViewPort.Modes & HIRES ) )
  302.                                 lastX >>= 1;
  303.                              Zoom();
  304.                             break;
  305.                         default:
  306.                             break;
  307.                         }
  308.                     break;
  309.                 case IDCMP_GADGETUP:
  310.                     gdg = (struct Gadget *)msg->IAddress;
  311.                     if ( gdg->GadgetID == ZOOM_IN_GDG_ID && scaling_factor < 40 )
  312.                         {
  313.                         FreeBitMaps();
  314.                         scaling_factor++;
  315.                         width = ( window->Width - window->BorderLeft - window->BorderRight -1 ) / scaling_factor;
  316.                         height = ( window->Height - window->BorderTop - window->BorderBottom -1 ) / scaling_factor;
  317.                         if ( stay = AllocBitMaps() )
  318.                             Zoom();
  319.                         }
  320.                     else
  321.                     if ( gdg->GadgetID == ZOOM_OUT_GDG_ID && scaling_factor > 2 )
  322.                         {
  323.                         FreeBitMaps();
  324.                         scaling_factor--;
  325.                         width = ( window->Width - window->BorderLeft - window->BorderRight -1 ) / scaling_factor;
  326.                         height = ( window->Height - window->BorderTop - window->BorderBottom -1 ) / scaling_factor;
  327.                         if ( stay = AllocBitMaps() )
  328.                             Zoom();
  329.                         }
  330.                     else
  331.                     if ( gdg->GadgetID == AUTO_PLUS_GDG_ID )
  332.                         {
  333.                         time_delay++;
  334.                         if ( timer_running == FALSE )
  335.                             {
  336.                             if ( timer_running = SetUpTimer() )
  337.                                 OnGadget( &AutoMinusGdg, window, NULL );
  338.                             }
  339.                         }
  340.                     else
  341.                     if ( gdg->GadgetID == AUTO_MINUS_GDG_ID )
  342.                         {
  343.                         if ( time_delay && timer_running )
  344.                             {
  345.                             time_delay--;
  346.                             RemoveTimer();
  347.                             if ( !time_delay )
  348.                                 {
  349.                                 timer_running = FALSE;
  350.                                 OffGadget( &AutoMinusGdg, window, NULL );
  351.                                 }
  352.                             else    SetUpTimer();
  353.                             }
  354.                         }
  355.                     SetTitles();
  356.                     break;
  357.                 default:
  358.                     break;
  359.                 }
  360.             ReplyMsg( (struct Message *)msg );
  361.             }
  362.         }
  363.     }
  364. }
  365.  
  366.  
  367. void main( int argc, char *argv[] )
  368. {
  369. if ( argc )
  370.     {
  371.     LONG args[6];
  372.     struct RDArgs *rdargs;
  373.  
  374.     memset( args, 0, 24 );
  375.     if ( rdargs = ReadArgs( "Auto/N,Scale/N,Left/N,Top/N,Width/N,Height/N", args, NULL ) )
  376.         {
  377.         if ( args[0] ) { time_delay = *((ULONG *)args[0]); timer_running = TRUE; }
  378.         if ( args[1] ) scaling_factor = *((ULONG *)args[1]);
  379.         if ( args[2] ) nwt.LeftEdge = *((ULONG *)args[2]);
  380.         if ( args[3] ) nwt.TopEdge = *((ULONG *)args[3]);
  381.         if ( args[4] ) nwt.Width = *((ULONG *)args[4]);
  382.         if ( args[5] ) nwt.Height = *((ULONG *)args[5]);
  383.         FreeArgs( rdargs );
  384.         }
  385.     }
  386. else
  387. if ( IconBase = OpenLibrary( "icon.library", 0L ) )
  388.     {
  389.     char **ttypes = ArgArrayInit( argc, argv );
  390.  
  391.     if ( time_delay = ArgInt( ttypes, "AUTO", 0 ) )
  392.         timer_running = TRUE;
  393.     scaling_factor = ArgInt( ttypes, "SCALE", 2 );
  394.     if ( scaling_factor < 2 || scaling_factor > 40 )
  395.         scaling_factor = 2;
  396.     nwt.LeftEdge = ArgInt( ttypes, "WLEFT", 60 );
  397.     nwt.TopEdge = ArgInt( ttypes, "WTOP", 60 );
  398.     nwt.Width = ArgInt( ttypes, "WWIDTH", 142 );
  399.     nwt.Height = ArgInt( ttypes, "WHEIGHT", 75 );
  400.  
  401.     ArgArrayDone();
  402.     CloseLibrary( IconBase );
  403.     }
  404.  
  405. if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 0L ) )
  406.     {
  407.     if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 0L ) )
  408.         {
  409.         if ( BitMapBase = OpenLibrary( "bitmap.library", 0L ) )
  410.             {
  411.             struct Screen *pubscr = LockPubScreen( NULL );
  412.             if ( pubscr )
  413.                 {
  414.                 depth = pubscr->RastPort.BitMap->Depth;
  415.  
  416.                 ZoomInGdg.TopEdge = pubscr->Font->ta_YSize + 3;
  417.                 ZoomOutGdg.TopEdge = ZoomInGdg.TopEdge + 10;
  418.                 AutoPlusGdg.TopEdge = ZoomOutGdg.TopEdge + 10;
  419.                 AutoMinusGdg.TopEdge = AutoPlusGdg.TopEdge + 10;
  420.  
  421.                 nwt.MaxWidth = pubscr->Width;
  422.                 nwt.MaxHeight = pubscr->Height;
  423.  
  424.                 if ( window = OpenWindow( &nwt ) )
  425.                     {
  426.                     SetTitles();
  427.                     SetAPen( window->RPort, 0 );
  428.                     SetPointer( window, Lens_data, 16L, 16L, -6, -6 );
  429.  
  430.                     if ( AllocBitMaps() )
  431.                         {
  432.                         bsi.bsi_SrcBitMap = pubscr->RastPort.BitMap;
  433.                         bsi.bsi_DestBitMap = /*bsi.bsi_SrcBitMap;*/destBm;
  434.                         bsi.bsi_TempBitMap = NULL;
  435.                         bsi.bsi_HorDen = 1;
  436.                         bsi.bsi_VertDen = 1;
  437.                         bsi.bsi_Flags = NULL;
  438.  
  439.                         if ( timer_running )
  440.                             timer_running = SetUpTimer();
  441.                         if ( !timer_running || !time_delay )
  442.                             OffGadget( &AutoMinusGdg, window, NULL );
  443.                         lastX = 0;
  444.                         lastY = 0;
  445.                         Zoom();
  446.                         ProcessMessages();
  447.                         FreeBitMaps();
  448.                         if ( timer_running )
  449.                             RemoveTimer();
  450.                         }
  451.                     ClearPointer( window );
  452.                     CloseWindow( window );
  453.                     }
  454.                 UnlockPubScreen( NULL, pubscr );
  455.                 }
  456.             CloseLibrary( BitMapBase );
  457.             }
  458.         CloseLibrary( (struct Library *)GfxBase );
  459.         }
  460.     CloseLibrary( (struct Library *)IntuitionBase );
  461.     }
  462. }
  463.